package ping 
{
	import com.junkbyte.console.Cc
	/**
	 * ...
	 * @author yaempechenki@gmail.com
	 */
	public class PingJenkins implements IPing
	{
		private const _url:String = "http://172.18.68.16:8080/job/BBSocialClient/rssAll";
		public function get URL():String {
			return _url;
		}
		
		public function ping(response:String):Boolean {
			var m:Array = [];
			var rule:String = '<entry><title>([^<]*)</title>';
			var regExp:RegExp = new RegExp(rule,"/g");
			m=response.match(regExp);
			for (var j:int = 0; j < m.length; j++) 
			{
				m[j] = getState(m[j]);
			}
			if (m && m.length > 0) {
				Cc.log("lastState", m[0]);
				return m[0] == "stable";
			}			
			return false;
		}
		
		private function getState(trashText:String):String {
			trashText = trashText.replace("</title>", "");
			trashText = trashText.replace("<entry><title>", "");
			if (trashText.search("stable")!=-1) {
				trashText = "stable";
			}
			if (trashText.search("back to normal") != -1) {
				trashText = "stable";
			}
			if (trashText.search("broken")!=-1) {
				trashText = "broken";
			}
			return trashText;
		}
	}
}